package com.learn.metrics.report.console;

import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;

import java.util.concurrent.TimeUnit;

/**
 * @author XuYang
 * @since 2025/2/19 11:21
 */
public class ConsoleReporterExample {
    public static void start(Integer interval) {
        MetricRegistry registry = new MetricRegistry();

        // 打印统计信息
        ConsoleReporter.forRegistry(registry).build().start(interval, TimeUnit.SECONDS);

        Meter meter = registry.meter("console");
        int count = 0;
        while (count++ < 10) {
            meter.mark();
            ThreadUtil.sleep(RandomUtil.randomInt(500, 1000));
        }
    }
}
